define(function (required, exports, modules) {
  var modal = require('mods/modal')
  exports.cal_set = function () {
    $(".calendar-save").click(function () {
      if ($(this).hasClass("disabled")) {
        modal.alert('系统真在处理中,请不要重复请求~~~')
        return false
      }

      var cal_value = $("input[name=date-value]").val()
      var cal_name = $('input[name=date-name]').val()
      var cal_history_today = $('#date_history_today').text()
      cal_history_today = cal_history_today.replace(/\r\n/g, '<br/>').replace(/\n/g, '<br/>').replace(/\s/g, ' '); //转换格式
      var cal_marketing = $('#date_marketing').val()
      cal_marketing = cal_marketing.replace(/\r\n/g, '<br/>').replace(/\n/g, '<br/>').replace(/\s/g, ' '); //转换格式
      var image_url = $('.image_url').val()
      var _csrf = $("#csrf").val()
      var cal_id = $('input[name=calendar-id]').val()

      if (cal_value.length < 1) {
        modal.alert("请填写日期")
        return false
      }
      if (cal_name.length < 1) {
        modal.alert("请填写日期标签")
        return false
      }

      $(this).addClass("disabled")
      $.ajax({
        url: '/admin/calendar/set',
        type: 'POST',
        dataType: 'json',
        data: {
          cal_value: cal_value,
          cal_name: cal_name,
          cal_history_today: cal_history_today,
          cal_marketing: cal_marketing,
          image_url:image_url,
          cal_id: cal_id,
          _csrf: _csrf
        },
        success: function (res) {
          $(this).removeClass("disabled")
          if (res.code == 200) {
            modal.msg(res.msg, {}, function () {
              location.href = '/admin/calendar/index'
            })
          } else {
            modal.alert(res.msg)
            return false
          }
        }
      })
    })
  }
})